﻿using System.Text;
using System;
using System.Collections.Generic;
using FarseerGames.FarseerPhysics;
using FarseerGames.FarseerPhysics.Collisions;
using FarseerGames.FarseerPhysics.Dynamics.Springs;
using FarseerGames.FarseerPhysics.Factories;
using PhysicsObjects;
using UnitLibrary.DrawingSystem;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;
using UnitLibrary;
using UnitLibrary.GameObjects.Physics;
using UnitLibrary.GameObjects;
using UnitLibrary.Utility;

namespace UnitLibrary.Managers
{    
    public class PointsM : UnitM<PhyObj>
    { 
       
        public PointsM(Game game, ComponentM gameScreen)
            : base(game, gameScreen, UnitID.Points)
        {
            base._maxObjects = 125;
        }

        private float _pointRange = 600f;

        public void AddPointObjects(int numberOfPoints, string pointName, Vector2 location)
        { 
            Vector2 direction = Vector2.One;
            for (int i = 0; i < numberOfPoints; i++) 
            { 
                direction.X = Utility.Util.random.Next(-10, 10);
                direction.Y = Utility.Util.random.Next(-10, 10);
                base.Create(pointName, location, direction); 
            } 
        }

        public override void Update(GameTime gameTime)
        {
            Vector2 playerposition = _components.playerManager.Player.Position;
            foreach (RPool<PhyObj>.Node unit in _unitPool.ActiveNodes)
            {
                if (Vector2.Distance(unit.Item.Position, playerposition) < _pointRange)
                {
                    unit.Item.SetMoveDirection(playerposition);
                    unit.Item.Move();
                }
                else if (unit.Item.DistanceFromSpawn() < 150f)
                    unit.Item.Move();
            }
            base.Update(gameTime);
        }
    }
}